package com.lds.config.center.server.business.app.controller;

import com.lds.config.center.common.model.app.request.AppBaseBatchCreateRequest;
import com.lds.config.center.common.model.app.request.AppBaseBatchDeleteRequest;
import com.lds.config.center.common.model.app.request.AppBaseBatchUpdateRequest;
import com.lds.config.center.common.model.app.request.AppBaseCreateRequest;
import com.lds.config.center.common.model.app.request.AppBaseDeleteRequest;
import com.lds.config.center.common.model.app.request.AppBaseGetByIdRequest;
import com.lds.config.center.common.model.app.request.AppBaseGetByIdsRequest;
import com.lds.config.center.common.model.app.request.AppBaseGetByKeyRequest;
import com.lds.config.center.common.model.app.request.AppBaseListPageRequest;
import com.lds.config.center.common.model.app.request.AppBaseListRequest;
import com.lds.config.center.common.model.app.request.AppBaseUpdateRequest;
import com.lds.config.center.common.model.app.response.AppBaseBatchCreateResponse;
import com.lds.config.center.common.model.app.response.AppBaseBatchDeleteResponse;
import com.lds.config.center.common.model.app.response.AppBaseBatchUpdateResponse;
import com.lds.config.center.common.model.app.response.AppBaseDeleteResponse;
import com.lds.config.center.common.model.app.response.AppBaseListResponse;
import com.lds.config.center.common.model.app.response.AppBaseResponse;
import com.lds.config.center.server.business.app.service.AppBaseService;
import com.lds.management.center.common.model.db.OrderBy;
import com.lds.management.center.common.model.db.PageResult;
import com.lds.management.center.common.model.dto.ResultDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2025-06-26
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/app")
public class AppBaseController {

    private final AppBaseService appBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<AppBaseResponse> createApp(@RequestBody @Validated AppBaseCreateRequest request) {
        return appBaseService.createApp(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<AppBaseBatchCreateResponse> batchCreateApp(@RequestBody @Validated AppBaseBatchCreateRequest request) {
        return appBaseService.batchCreateApp(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<AppBaseDeleteResponse> deleteApp(@RequestBody AppBaseDeleteRequest request) {
        return appBaseService.deleteApp(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<AppBaseBatchDeleteResponse> batchDeleteApp(@RequestBody @Validated AppBaseBatchDeleteRequest request) {
        return appBaseService.batchDeleteApp(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<AppBaseResponse> updateApp(@RequestBody @Validated AppBaseUpdateRequest request) {
        return appBaseService.updateApp(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<AppBaseBatchUpdateResponse> batchUpdateApp(@RequestBody @Validated AppBaseBatchUpdateRequest request) {
        return appBaseService.batchUpdateApp(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<AppBaseListResponse> listApp(@RequestBody AppBaseListRequest request) {
        return appBaseService.listApp(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<AppBaseListResponse> listAllApp(@RequestBody OrderBy orderBy) {
        return appBaseService.listAllApp(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<AppBaseResponse> getAppById(@RequestBody @Validated AppBaseGetByIdRequest request) {
        return appBaseService.getAppById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<AppBaseListResponse> getAppByIds(@RequestBody @Validated AppBaseGetByIdsRequest request) {
        return appBaseService.getAppByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<AppBaseResponse>> listAppPage(@RequestBody AppBaseListPageRequest request) {
        return appBaseService.listAppPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated AppBaseGetByKeyRequest request) {
        return ResultDTO.success(appBaseService.getAppByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<AppBaseBatchCreateResponse> batchCreateAppAsync(@RequestBody @Validated AppBaseBatchCreateRequest request) {
        return appBaseService.batchCreateAppAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<AppBaseBatchDeleteResponse> batchDeleteAppAsync(@RequestBody @Validated AppBaseBatchDeleteRequest request) {
        return appBaseService.batchDeleteAppAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<AppBaseBatchUpdateResponse> batchUpdateAppAsync(@RequestBody @Validated AppBaseBatchUpdateRequest request) {
        return appBaseService.batchUpdateAppAsync(request);
    }

}